home *** CD-ROM | disk | FTP | other *** search
- unit DockedControls8U;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, ToolWin, StdCtrls, ImgList, ExtCtrls, ActnList, Menus;
-
- type
- TForm1 = class(TForm)
- ImageList1: TImageList;
- Label1: TLabel;
- Panel1: TPanel;
- Image1: TImage;
- MainMenu1: TMainMenu;
- ActionList1: TActionList;
- actToggleToolbar: TAction;
- Environment1: TMenuItem;
- Toolbarvisible1: TMenuItem;
- btnToggleFloat: TButton;
- ToolBar1: TToolBar;
- ToolButton6: TToolButton;
- ToolButton7: TToolButton;
- ToolButton8: TToolButton;
- ToolButton9: TToolButton;
- ToolButton10: TToolButton;
- TopDockPanel: TPanel;
- RightDockPanel: TPanel;
- LeftDockPanel: TPanel;
- BottomDockPanel: TPanel;
- procedure FormCreate(Sender: TObject);
- procedure actToggleToolbarExecute(Sender: TObject);
- procedure actToggleToolbarUpdate(Sender: TObject);
- procedure btnToggleFloatClick(Sender: TObject);
- procedure DockPanelGetSiteInfo(Sender: TObject; DockClient: TControl;
- var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean);
- procedure DockPanelDockOver(Sender: TObject;
- Source: TDragDockObject; X, Y: Integer; State: TDragState;
- var Accept: Boolean);
- procedure DockPanelDockDrop(Sender: TObject;
- Source: TDragDockObject; X, Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Mouse.DragImmediate := False;
- Image1.ManualDock(Panel1);
- ToolBar1.ManualDock(TopDockPanel);
- end;
-
- procedure TForm1.actToggleToolbarExecute(Sender: TObject);
- begin
- ToolBar1.Visible := not (Sender as TAction).Checked
- end;
-
- procedure TForm1.actToggleToolbarUpdate(Sender: TObject);
- begin
- (Sender as TAction).Checked := ToolBar1.Visible
- end;
-
- procedure TForm1.btnToggleFloatClick(Sender: TObject);
- begin
- if ToolBar1.Floating then
- ToolBar1.ManualDock(TopDockPanel)
- else
- //ToolBar1.ManualDock(nil)
- ToolBar1.ManualFloat(
- Rect(Left, Top, Left + ToolBar1.UndockWidth, Top + ToolBar1.UndockHeight))
- end;
-
- procedure TForm1.DockPanelGetSiteInfo(Sender: TObject; DockClient: TControl;
- var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean);
- begin
- //Allow for more margin of error
- InflateRect(InfluenceRect, 10, 10);
- //Only accept toolbars
- CanDock := DockClient is TToolBar
- end;
-
- procedure TForm1.DockPanelDockOver(Sender: TObject;
- Source: TDragDockObject; X, Y: Integer; State: TDragState;
- var Accept: Boolean);
- var
- DockBar: TToolBar;
- InflateSize: Integer;
- ARect: TRect;
- ClientTL: TPoint;
- begin
- DockBar := Source.Control as TToolBar;
- //Get current height if horizontal or width if vertical
- if DockBar.Width > DockBar.Height then
- InflateSize := DockBar.Height
- else
- InflateSize := DockBar.Width;
- //Dock rect will be 0 width/height as per the panel dimensions
- //To make it look realistic, increase rectangle
- //to same width/height as toolbar
- ARect := Source.DockRect;
- case (Sender as TPanel).Align of
- alTop: Inc(ARect.Bottom, InflateSize);
- alLeft: Inc(ARect.Left, InflateSize);
- alBottom: Dec(ARect.Top, InflateSize);
- alRight: Dec(ARect.Right, InflateSize);
- end;
- //Two of the four aligned dock panels will not stretch
- //along edge of form client area (because of the currently
- //visible one's size). Make sure dock rectangles do
- ClientTL := Point(0, 0);
- ClientTL := ClientToScreen(ClientTL);
- case (Sender as TPanel).Align of
- alTop, alBottom:
- begin //Make horizontal panels stretch across form's client width
- ARect.Left := ClientTL.X;
- ARect.Right := ClientTL.X + ClientWidth;
- end;
- alLeft, alRight:
- begin //Make vertical panels stretch across form's client width
- ARect.Top := ClientTL.Y;
- ARect.Bottom := ClientTL.Y + ClientHeight;
- end;
- end;
- Source.DockRect := ARect
- end;
-
- procedure TForm1.DockPanelDockDrop(Sender: TObject;
- Source: TDragDockObject; X, Y: Integer);
- begin
- //Get toolbar to reset its dimensions for docking
- (Source.Control as TToolBar).Align := (Sender as TPanel).Align;
- end;
-
- end.
-